package com.free.semantic.core.impl.demo;

import com.free.semantic.common.Ls;
import com.free.semantic.common.ParamNode;
import com.free.semantic.common.RelationChain;
import com.free.semantic.core.ConceptManage;
import com.free.semantic.core.impl.BaseTest;
import com.free.semantic.core.impl.ConceptInstanceManageImpl;
import com.free.semantic.core.impl.demo.sample.baseConcept.BaseConcept;
import com.free.semantic.core.impl.demo.sample.memoryStoreImpl.DefaultMemoryConceptInstanceImpl;
import com.free.semantic.facade.Link;
import com.free.semantic.facade.Node;
import com.free.semantic.utils.Utils;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * 即插即用式架构体现demo，定义语义网络后，通过继承大家共识的基础概念，表达自己的目标，使用默认实现器自动完成实现。
 * 未来的操作流程：
 * 1. 定义属于自己的语义网络结构
 * 2. 根据自己的目标搜索 各种实现器
 * 3. 根据实现器的描述，将自己的概念继承 实现器的概念完成目标的表达
 * 4. 默认实现器自动完成目标
 */
public class Demo5_mixArchitecture extends BaseTest {

    @Test
    public void test() {

        ConceptManage concept = BaseConcept.getDefaultConcept();

        //创建属性
        concept.addConcept("支付单", "订单编号", "创建时间", "商家编号");
        Utils.createRelation(concept, "属性", "支付单", "订单编号");
        Utils.createRelation(concept, "属性", "支付单", "创建时间");
        Utils.createRelation(concept, "属性", "支付单", "商家编号");

        //标识自己的目标
        Utils.createRelation(concept, "继承", "支付单", "entity");

        //使用默认实现器 创建自己的实现
        DefaultMemoryConceptInstanceImpl impl = new DefaultMemoryConceptInstanceImpl(concept);

        // 创建实例
        ConceptInstanceManageImpl instanceManage = new ConceptInstanceManageImpl(concept, impl);

        //查询创建路径和参数
        List<RelationChain> chainList = instanceManage.concept().findExactRelationChain(Ls.of("支付单_concept"), "支付单_create");
        System.out.println(chainList);

        //执行创建函数，创建三个订单 //todo 目前框架暂时不支持重复名称，自动创建了 支付单_create等概念，理想状态应该是  create
        instanceManage.takePath(Ls.of(
                new ParamNode("支付单_concept"),
                new ParamNode("订单编号", "aaaa"),
                new ParamNode("创建时间", "2025-02-22"),
                new ParamNode("商家编号", "No-aaaa")), "支付单_create");

        instanceManage.takePath(Ls.of(
                new ParamNode("支付单_concept"),
                new ParamNode("订单编号", "bbbb"),
                new ParamNode("创建时间", "2025-02-23"),
                new ParamNode("商家编号", "No-bbbb")), "支付单_create");

        instanceManage.takePath(Ls.of(
                new ParamNode("支付单_concept"),
                new ParamNode("订单编号", "ccccc"),
                new ParamNode("创建时间", "2025-02-24"),
                new ParamNode("商家编号", "No-ccccc")), "支付单_create");

        List<Long> allOrder = instanceManage.takePath(
                Ls.of(new ParamNode("pageParam")), "支付单");
        System.out.println(allOrder);


        List<Node> allNode = concept.getAllNode();
        List<Link> allLink = concept.getAllLink();


        System.out.println(allNode);
        System.out.println(allLink);


        assert allOrder.size() == 3;

        Long payOrder = allOrder.get(0);

        // 查询该支付单的订单编号
        String orderNo = (String) instanceManage.takePath(Ls.of(new ParamNode("支付单", payOrder)), "订单编号").get(0);

        System.out.println(orderNo);
        assert orderNo.equals("aaaa");

        // TODO  执行更新函数



        //执行删除函数
        instanceManage.takePath(Ls.of(new ParamNode("支付单", allOrder)), "支付单_delete");


        List<Long> leftOrder = instanceManage.takePath(Ls.of(new ParamNode("pageParam", null)), "支付单");
        System.out.println(leftOrder);

        assert leftOrder.size() == 0;

    }

}
